package com.hgy.commonsale.webui.action;

import org.geln.web.context.ISessionContext;


import com.hgy.commonsale.service.AdminManagerService;
import com.hgy.commonsale.user.domain.Admin;


public class AdminLoginAction extends AnonymousAction {
	
	private static final String DEFAULT_URL = "index.action";
	
	private String adminName;
	private String adminPassword;
	private AdminManagerService adminManagerService;
	
	public String getAdminName() {
		return adminName;
	}
	public void setAdminName(String adminName) {
		this.adminName = adminName;
	}
	public String getAdminPassword() {
		return adminPassword;
	}
	public void setAdminPassword(String adminPassword) {
		this.adminPassword = adminPassword;
	}
	
	public String getOriginalURL() {
		try {
			String url = (String) sessionContext.getResource(ISessionContext.ORIGINAL_URL);
			sessionContext.unbindResource(ISessionContext.ORIGINAL_URL);
			return url;
		} catch (Exception E) {
			return DEFAULT_URL;
		}
	}
	
	
	public String execute() throws Exception {
		
		Admin admin=adminManagerService.getAdminByAdminName(adminName);
		if(admin==null){
			addActionError(getText("admin.login.error"));
			return INPUT;
		}else{
			if(adminPassword!=null){
				if(admin.getAdminPassword().equals(adminPassword)){
					return SUCCESS;
				}
				
			}
			else{
				addActionError(getText("admin.login.passwordWrong"));
				return INPUT;
			}
		}	
		
		return INPUT;
	}
	
	public AdminManagerService getAdminManagerService() {
		return adminManagerService;
	}
	public void setAdminManagerService(AdminManagerService adminManagerService) {
		this.adminManagerService = adminManagerService;
	}
	
	
	
	

}
